define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form){

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'financing/cost/index',
                    add_url: 'financing/cost/add',
                    //edit_url: 'financing/cost/edit',
                    //del_url: 'users/user/del',
                    //for_url: 'financing/accepts/for',
                    multi_url: 'financing/cost/multi',
                    table: 'cost',
                }
            });

            var table = $("#table");

            //console.log($('#table').bootstrapTable('getAllSelections'));
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                //sortName: 'user.id',
                commonSearch: true,
                searchFormVisible: true,
                visible: false,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('序号'), formatter: function(value, row, index){
                                return ++index;
                            }, operate: false},
                        {field: 'user_id', title: __('客户id'), operate: 'LIKE'},
                        {field: 'users.nickname', title: __('昵称'), operate: false},
                        {field: 'users.phone', title: __('手机号'), operate: false},
                        {field: 'cost_way', title: __("费用方式"), searchList: {"1":__('会籍费'),"2":__('续费'),"3":__('成员费用')}, formatter: Table.api.formatter.status},
                        {field: 'money', title: __('收款金额'), operate: false},
                        {field: 'pay', title: __('支付方式'), operate: false},
                        {field: 'admin_name', title: __('收款人'), operate: false},
                        {field: 'vip_time', title: __('会员到期时间'), operate: false},
                        //{field: 'image', title: __('头像'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        //{field: 'draw', title: __('抽奖次数'), operate: false, sortable: true},
                        //{field: 'on_credit', title: __("状态"), searchList: {"1":__('未补缴'),"2":__('已补交')}, formatter: Table.api.formatter.status},
                        //{field: 'userss.name', title: __('上级姓名'), operate: 'LIKE', sortable: true},
                        {field: 'create_time', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}

                        // {field: 'operate', title: __('Operate'), table: table,
                        //     events: Table.api.events.operate,
                        //     buttons: [{
                        //         name: 'detail',
                        //         //extend: 'data-area=\'["100%", "100%"]\'',
                        //         text: __('补交'),
                        //         icon: 'fa fa-list',
                        //         classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                        //         url: 'financing/supplementary/fors'
                        //     }],
                        //     formatter: Table.api.formatter.operate
                        //
                        // },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }

    };
    return Controller;
});